let { $, table, form } = layui;
export default class Search {
    constructor(tableIns) {
        this.handle(tableIns);
    }
    handle(tableIns) {
        let type = $('[name="type"]').val();
        let value = $('[name="value"]').val();
        console.log(type, value);
        if (value) {
            tableIns.reload({
                parseData(res) {
                    console.log(res.data.rows);
                    let data = [];
                    if (type == 'films') {
                        data = res.data.rows.filter((item) => {
                            if (item.films["name"].indexOf(value) >= 0) {
                                return item;
                            }
                        })
                    } else {
                        data = res.data.rows.filter((item) => {
                            if (item.cinemas["name"].indexOf(value) >= 0) {
                                return item;
                            }
                        })
                    }
                    res.data.rows = data;
                    res.data.total = data.length;
                    return {
                        "code": 0,
                        "count": res.data.total,
                        "data": res.data.rows
                    }
                },
                where: {
                    current: 1
                }
            })
        }
    }
}